package designpattern.state;

public class GumballMachine {
	public final static int SOLD_OUT = 0;
	public final static int NO_QUARTER = 1;
	public final static int HAS_QUARTER = 2;
	public final static int SOLD = 3;
	
	State soldOut;
	State noQuarter;
	State hasQuarter;
	State sold;
	
	State state = sold;
	int count = 0;
	
	public GumballMachine(int numberGumballs) {
		this.noQuarter = new NoQuarterState(this);
		this.sold = new SoldState(this);
		this.hasQuarter = new HasQuarterState(this);
		
		this.count = numberGumballs;
		if(numberGumballs > 0) {
			this.state = noQuarter;
		}
	}
	/**
	 * @return the state
	 */
	public State getState() {
		return state;
	}
	/**
	 * @param state the state to set
	 */
	public void setState(State state) {
		this.state = state;
	}
	/**
	 * @return the soldOut
	 */
	public State getSoldOut() {
		return soldOut;
	}
	/**
	 * @return the noQuarter
	 */
	public State getNoQuarter() {
		return noQuarter;
	}
	/**
	 * @return the hasQuarter
	 */
	public State getHasQuarter() {
		return hasQuarter;
	}
	/**
	 * @return the sold
	 */
	public State getSold() {
		return sold;
	}
	
	public void releaseGumball() {
		System.out.println("The machine is rolling out a ball.");
		if(count > 0) {
			count--;
		}
	}
	
}
